package com.inspection.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {

  @Bean
  public Docket restApi() {

    return new Docket(DocumentationType.SWAGGER_2)
        .apiInfo(apiInfo())
        .groupName("inspection")
        .forCodeGeneration(true)
        .genericModelSubstitutes(ResponseEntity.class)
        .useDefaultResponseMessages(false)
        // .enableUrlTemplating(true)
        /*.pathMapping("/")*/
        .select()
        .apis(RequestHandlerSelectors.basePackage("com.inspection"))
        .build();
  }

  ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("RESTful API")
        .description("RESTful API Documentation")
        .version("1.0.0")
        /*.termsOfServiceUrl("http://newstyle.com/")
        .contact(new Contact("fox_qian", "", "qianhang@entgroup.com"))*/
        .license("Apache License, Version 2.0")
        .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
        .build();
  }

}
